//
//  CZDiscoverSearchView.swift
//  WeiBo
//
//  Created by Apple on 16/9/4.
//  Copyright © 2016年 KY. All rights reserved.
//

import UIKit

class CZDiscoverSearchView: UIView, UITextFieldDelegate {

    @IBOutlet weak var searchTextField: UITextField!
    
    @IBOutlet weak var searchTextFieldTrailingConstraints: NSLayoutConstraint!
    //  类方法实例化xib对象
    class func discoverSearchView() -> CZDiscoverSearchView {
        
        //  加载xib对象
        return UINib(nibName: "CZDiscoverSearchView", bundle: nil).instantiate(withOwner: nil, options: nil).last! as! CZDiscoverSearchView
        
        
    }
    
    
    @IBAction func btnSearchAction(_ sender: AnyObject) {
        //  取消第一响应者
        searchTextField.resignFirstResponder()
        
        searchTextFieldTrailingConstraints.constant = 0
        
        UIView.animate(withDuration: 0.25) { 
            self.layoutIfNeeded()
        }
        
    }
    
    //  开始编辑
    func textFieldDidBeginEditing(_ textField: UITextField) {
        
        //  设置约束
        searchTextFieldTrailingConstraints.constant = 46
        //  约束动画
        UIView.animate(withDuration: 0.25) {
            
            //  子控件重写布局
            self.layoutIfNeeded()
        }

    }
    
}
